package demo.partten.filterPattern;

import demo.partten.filterPattern.pattern.Criteria;
import demo.partten.filterPattern.pattern.Person;
import demo.partten.filterPattern.pattern.impl.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SimpleTest {

    private static final Map<String,Criteria> map = new HashMap<>();

    static {
        Criteria male = new CriteriaMale();
        Criteria female = new CirteriaFemale();
        Criteria single = new CriteriaSingle();

        List<Criteria> singleAndMaleList = new ArrayList<>();
        singleAndMaleList.add(male);
        singleAndMaleList.add(single);
        Criteria singleAndMale = new AndCriteria(singleAndMaleList);

        List<Criteria> singleAndFeMaleList = new ArrayList<>();
        singleAndFeMaleList.add(female);
        singleAndFeMaleList.add(single);
        Criteria singleAndFeMale = new AndCriteria(singleAndFeMaleList);

        List<Criteria> orList = new ArrayList<>();
        orList.add(singleAndMale);
        orList.add(singleAndFeMale);
        Criteria total = new OrCriteria(orList);
        map.put("total",total);
    }

    public static void main(String[] args) {
        List<Person> persons = new ArrayList<Person>();

        persons.add(new Person("Robert",1, "Married"));
        persons.add(new Person("John",1, "Married"));
        persons.add(new Person("Laura",0, "Married"));
        persons.add(new Person("Diana",0, "Single"));
        persons.add(new Person("Mike",1, "Single"));
        persons.add(new Person("Bobby",2, "Single")); // 单身 第三性别

        map.get("total").meetCriteria(persons).forEach(System.out::println); // 核心语句


    }

}
